/*************************************************************************
Crytek Source File.
Copyright (C), Crytek Studios, 2001-2008.
-------------------------------------------------------------------------
$Id: DiskProfiler.h,v 1.0 2008/03/28 11:11:13 AntonKaplanyan Exp wwwrun $
$DateTime$
Description:  Routine for profiling disk IO
-------------------------------------------------------------------------
History:
- 28:3:2008   11:11 : Created by Anton Kaplanyan
*************************************************************************/


#ifndef __diskprofilesystem_h__
#define __diskprofilesystem_h__
#pragma once

#include <IDiskProfiler.h>
#include <IStreamEngine.h>
#include <CryThread.h>
#include <Cry_Color.h>

#ifdef USE_DISK_PROFILER

//////////////////////////////////////////////////////////////////////////
// Disk Profile main class
//////////////////////////////////////////////////////////////////////////
class CDiskProfiler : public IDiskProfiler
{
	friend class CDiskProfileTimer;
public:
	CDiskProfiler(ISystem* pSystem);
	~CDiskProfiler();
	VIRTUAL void Update();						// perframe update routine
	VIRTUAL DiskOperationInfo GetStatistics() const {
		return m_outStatistics;
	}
	VIRTUAL bool RegisterStatistics(SDiskProfileStatistics* pStatistics);		// main statistics registering function

	VIRTUAL void SetTaskType(const uint32 nThreadId, const uint32 nType = 0xffffffff);		// task type registering function

	VIRTUAL bool IsEnabled() const;

protected:

	// rendering routine
	void RenderBlock(const float timeStart, const float timeEnd, const ColorB threadColor, const ColorB IOTypeColor);
	void Render();

	typedef std::deque<SDiskProfileStatistics*> Statistics;
	typedef std::map<uint32, ColorB> ThreadColorMap;
	typedef std::map<uint32, EStreamTaskType, std::less<uint32>, stl::STLGlobalAllocator<std::pair<uint32, EStreamTaskType> > > ThreadTaskTypeMap;

	volatile bool						m_bEnabled;
	CryCriticalSection			m_csLock;				// MT-safe profiling
	Statistics							m_statistics;		// main statistics collector
	ThreadColorMap					m_threadsColorLegend;
	ThreadTaskTypeMap				m_currentThreadTaskType;
	ISystem*								m_pSystem;

	int											m_nHeightOffset;	// offset from bottom of the screen, in pixels

	DiskOperationInfo				m_outStatistics;
public:
	static int profile_disk;
	static int profile_disk_max_items;
	static int profile_disk_max_draw_items;
	static float profile_disk_timeframe;		// max time for profiling timeframe
	static int profile_disk_type_filter;		// filter by task types for profiling
	static int profile_disk_budget;		// filter by task types for profiling
};

#endif

#endif // __diskprofilesystem_h__
